package com.google.code.alpaca.prototype.handler;

import javax.inject.Inject;

import net.customware.gwt.dispatch.server.ActionHandler;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.DispatchException;

import com.google.code.alpaca.prototype.dao.MessageDAO;
import com.google.code.alpaca.prototype.rpc.MessageActions.DeleteMessageAction;
import com.google.code.alpaca.prototype.rpc.VoidResult;
import com.google.inject.persist.Transactional;

public class DeleteMessageHandler implements
		ActionHandler<DeleteMessageAction, VoidResult> {

	@Inject
	private MessageDAO messageRepository;

	@Override
	public Class<DeleteMessageAction> getActionType() {
		return DeleteMessageAction.class;
	}

	@Transactional
	@Override
	public VoidResult execute(DeleteMessageAction action,
			ExecutionContext context) throws DispatchException {
		messageRepository.deleteById(action.get());
		return VoidResult.VOID;
	}

	@Override
	public void rollback(DeleteMessageAction action, VoidResult result,
			ExecutionContext context) throws DispatchException {
	}

}
